package _12_avl_tree.case2;

import org.junit.Test;

/**
 * @author: mornd
 * @dateTime: 2023/6/15 - 17:25
 */
public class MyTest {
    @Test
    public void test() {
        AVLTree avlTree = new AVLTree();
        for (int i = 1; i <= 10; i++) {
            avlTree.put(i, null);
        }
        System.out.println(avlTree);
        System.out.println("----------------------------------------------");
        avlTree.remove(8);
        System.out.println(avlTree);
    }

    @Test
    public void test2() {
        // 1,2,3,4,5,6,7,8,9,11,12,13,14,15,16,17,18,19,20,21
        AVLTree<Integer> avlTree = new AVLTree<>();
        AVLTree.AVLNode root = avlTree.new AVLNode(14, 6);
        avlTree.root =root;
        root.left = avlTree.new AVLNode(9, 5);
        root.left.left = avlTree.new AVLNode(5, 4);
        root.left.left.left = avlTree.new AVLNode(3, 3);
        root.left.left.left.left = avlTree.new AVLNode(2, 2);
        root.left.left.left.left.left = avlTree.new AVLNode(1);
        root.left.left.left.right = avlTree.new AVLNode(4);
        root.left.left.right = avlTree.new AVLNode(7, 2);
        root.left.left.right.left = avlTree.new AVLNode(6);
        root.left.left.right.right = avlTree.new AVLNode(8);
        root.left.right = avlTree.new AVLNode(12, 3);
        root.left.right.left = avlTree.new AVLNode(10, 2);
        root.left.right.left.right = avlTree.new AVLNode(11);
        root.left.right.right = avlTree.new AVLNode(13);
        root.right = avlTree.new AVLNode(19, 4);
        root.right.left = avlTree.new AVLNode(16, 3);
        root.right.left.left = avlTree.new AVLNode(15);
        root.right.left.right = avlTree.new AVLNode(17, 2);
        root.right.left.right.right = avlTree.new AVLNode(18);
        root.right.right = avlTree.new AVLNode(20, 2);
        root.right.right.right = avlTree.new AVLNode(21);

        System.out.println(avlTree);
        System.out.println("==================================================");
        avlTree.remove(9);
        System.out.println("\n" + avlTree);
    }
}
